﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyLib.Web.UI {
	/// <summary>
	/// 
	/// </summary>
	[DefaultProperty("Text")]
	[ToolboxData("<{0}:MyLiteral runat=\"server\" ></{0}:MyLiteral>")]
	public class MyLiteral : WebControl, ITextControl {

		#region ITextControl

		/// <summary>
		/// 
		/// </summary>
		[Category("Appearance")]
		[Bindable(true, BindingDirection.TwoWay)]
		[Browsable(true)]
		public string Text {
			get {
				var obj = ViewState["Text"];

				if (obj == null) {
					return "";
				} else {
					return (string)obj;
				}
			} // end of get.
			set {
				ViewState["Text"] = value;
			} // end of set.
		}

		#endregion

		/// <summary>
		/// 
		/// </summary>
		public MyLiteral()
			: base(HtmlTextWriterTag.Span) {
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="writer"></param>
		protected override void RenderContents(HtmlTextWriter writer) {
			if (!string.IsNullOrEmpty(Text)) {
				HttpUtility.HtmlEncode(Text, writer);
			}
		}
	} // end of MyLiteral.
}
